﻿// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "StarrySkyPlayerController.generated.h"

class USplineComponent;
class UStarrySkyAbilitySystemComponent;
struct FGameplayTag;
class UStarrySkyInputConfig;
class IEnemyInterface;
struct FInputActionValue;
class UInputMappingContext;
class UInputAction;
/**
 * 
 */
UCLASS()
class STARRYSKY_API AStarrySkyPlayerController : public APlayerController
{
	GENERATED_BODY()
	
public:
	AStarrySkyPlayerController();
	virtual void PlayerTick(float DeltaTime) override;
	// 平滑旋转参数
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Rotation")
	float RotationInterpSpeed = 10.0f;
protected:
	virtual void BeginPlay() override;
	virtual void SetupInputComponent() override;
private:
	UPROPERTY(EditAnywhere,Category="Input")
	TObjectPtr<UInputMappingContext> AuraContext;
	UPROPERTY(EditAnywhere,Category="Input")
	TObjectPtr<UInputAction> MoveAction;
	//角色瞄准方向
	UPROPERTY(EditAnywhere,Category="Input")
	TObjectPtr<UInputAction> LookUpAction;
	UPROPERTY(EditAnywhere,Category="Input")
	TObjectPtr<UInputAction> ShiftAction;

	//角色移动方法
	void Move(const FInputActionValue& InputActionValue);
	//角色移动方法,通过鼠标移动到指定目标点
	void AutoRun();
	//角色瞄准方法
	void LookUp(const float DeltaTime);
	//实现了敌人接口的对象，存储被选中的敌人
	IEnemyInterface* LastActor;
	IEnemyInterface* ThisActor;
	void CursorTrace();
	FHitResult CursorHit;//鼠标点击位置，光标检测射线的命中目标
	
	//输入回调函数
	void AbilityInputTagPressed(FGameplayTag InputTag);
	void AbilityInputTagReleased(FGameplayTag InputTag);
	void AbilityInputTagHeld(FGameplayTag InputTag);

	UPROPERTY(EditDefaultsOnly,Category="Input")
	TObjectPtr<UStarrySkyInputConfig> InputConfig;

	UPROPERTY(VisibleAnywhere)
	TObjectPtr<USplineComponent> Spline;//玩家顺滑的一路径
	
	//能力系统组件
	UPROPERTY()
	TObjectPtr<UStarrySkyAbilitySystemComponent> StarrySkyAbilitySystemComponent;

	UStarrySkyAbilitySystemComponent* GetAsc();//获取Asc StarrySky能力系统组件，方便使用
	
	//平滑旋转的计算参数
	FRotator TargetRotation;
	bool bHasValidTarget = false;
	float FollowTime=0.f;//刷新点击时间,按住的时间用来和短按阈值判断是否是点击
	float ShortPressThreshold=0.5f;//短按的时间阈值
	bool bAutoRunning=false;//是否未点击一个点自动移动
	bool bTargeting=false;//是否旋转一个目标
	UPROPERTY(EditDefaultsOnly)
	float AutoRunAcceptanceRadius=50.f;//自动移动目的点的半径
	FVector CachedDestination=FVector::ZeroVector;//缓存鼠标点击位置
};

